<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Abuse: this is abuses table
 * manage abusing of people
 *
 * @author tuancasi
 * 
 * properties of this table
 * @property int $abuse_id 
 * @property int $post_id
 * @property int $user_id
 * @property int $link_post
 * @property string $message
 * @property int $time_created
 */
class Abuse extends CActiveRecord {

    public $sender = '';
    public $postTitle = '';

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return User the static model class
     */
    public static function model($className = __CLASS__) {
	return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
	return '{{abuses}}';
    }

    public function rules() {
	return array(
	    array('abuse_id, post_id, user_id, link_post, message, time_created, sender, postTile', 'safe')
	);
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
	// NOTE: you may need to adjust the relation name and the related
	// class name for the relations automatically generated below.
	return array(
	    'posts' => array(self::BELONGS_TO, 'Ad', 'post_id'),
	    'user' => array(self::BELONGS_TO, 'User', 'user_id')
	);
    }

    public function search() {
	// Warning: Please modify the following code to remove attributes that
	// should not be searched.

	$criteria = new CDbCriteria;
	$criteria->with = array("user", "posts");
	$criteria->alias = 't';
	$criteria->compare('user.display_name', $this->sender, true);
	$criteria->compare('posts.title', $this->postTitle, true);
	$criteria->compare('message', $this->message, true);
	//order
	$criteria->order = 't.time_created DESC';

	return new CActiveDataProvider($this, array(
	    'criteria' => $criteria,
	    'pagination' => array(
		'pageSize' => param('pageSize')
	    )
	));
    }

}

?>
